package com.sqx.modules.pay.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sqx.common.utils.PageUtils;
import com.sqx.common.utils.Result;
import com.sqx.modules.pay.dao.PayClassifyDao;
import com.sqx.modules.pay.dao.PayDetailsDao;
import com.sqx.modules.pay.dao.UserDramaDetailsDao;
import com.sqx.modules.pay.entity.PayClassify;
import com.sqx.modules.pay.entity.PayDetails;
import com.sqx.modules.pay.entity.UserDramaDetails;
import com.sqx.modules.pay.service.PayDetailsService;
import com.sqx.modules.pay.service.UserDramaDetailsService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserDramaDetailsServiceImpl extends ServiceImpl<UserDramaDetailsDao, UserDramaDetails> implements UserDramaDetailsService {


    @Autowired
    private UserDramaDetailsDao userDramaDetailsDao;

    @Autowired
    private PayClassifyDao payClassifyDao;
    /**
     * 查询用户剧点详情列表
     * @param userId
     * @param page
     * @param limit
     * @return
     */
    @Override
    public Result getDramaDetailsList(Long userId, Integer page, Integer limit) {
        Page<UserDramaDetails> detailsPage = new Page<>(ObjectUtils.isNotEmpty(page) ? page : 1, ObjectUtils.isNotEmpty(limit) ? limit : 10);
        LambdaQueryWrapper<UserDramaDetails> userDramaDetailsLambdaQueryWrapper = new LambdaQueryWrapper<>();
        userDramaDetailsLambdaQueryWrapper.eq(UserDramaDetails::getUserId,userId);
        userDramaDetailsLambdaQueryWrapper.orderByDesc(UserDramaDetails::getCreateTime);
        IPage<UserDramaDetails> selectPage = userDramaDetailsDao.selectPage(detailsPage, userDramaDetailsLambdaQueryWrapper);
        return Result.success().put("data",new PageUtils(selectPage));
    }

    /**
     * 剧点列表
     * @return
     */
    @Override
    public Result getPointList() {
        LambdaQueryWrapper<PayClassify> payClassifyLambdaQueryWrapper = new LambdaQueryWrapper<>();
        payClassifyLambdaQueryWrapper.eq(PayClassify::getStatus,1);
        return Result.success().put("data",payClassifyDao.selectList(payClassifyLambdaQueryWrapper));
    }
}
